<?php
namespace Home\Controller;
use Think\Controller;
use App\Controller\BaseController;
class TutorialController extends BaseController {

    public function _initialize(){
        //php判断客户端是否为手机
        $agent = $_SERVER['HTTP_USER_AGENT'];
        if(strpos($agent,"NetFront") || strpos($agent,"iPhone") || strpos($agent,"MIDP-2.0") || strpos($agent,"Opera Mini") || strpos($agent,"UCWEB") || strpos($agent,"Android") || strpos($agent,"Windows CE") || strpos($agent,"SymbianOS"))
        header("Location:http://xuancode.com/midi/index.php/Web/");
        //如果session存在，传递用户信息
        $midiuser = session('midiuser');
        $this->assign('midiuser',$midiuser);
    }
    //曲谱教程列表页
    public function index(){
    	//筛选条件
        $type = I('type',1,'intval');
        //查询数据
        $data = M('goods')
            ->field('goods_num,goods_file,goods_display',true)
            ->where(['goods_major_id'=>$type,'goods_display'=>1])
            ->order('goods_level')
            ->select();
        $this->assign('type',$type);
        $this->assign('data',$data);
        $this->display();
    }

    public function detail(){
        $id = I('id',0,'intval');
    	$info = M('goods')
            ->field('goods_num,goods_file,goods_display',true)
            ->where(['goods_id'=>$id,'goods_display'=>1])
            ->find();
    	if(empty($info)){
    	    $this->redirect('index');
        }
    	$this->assign('info',$info);
    	$this->display();
    }
}